import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import '../../component/mine/index.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:url_launcher/url_launcher.dart';

class TabMine extends StatefulWidget {
  const TabMine({ Key key }) : super(key: key);

  @override
  TabMineState createState() => TabMineState();
}

class TabMineState extends State<TabMine> {
  Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
  int _counter = 0;
  dynamic mineTopWidge = new MineTop();

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    new Future.delayed(const Duration(seconds: 3),(){
      print('Duration');
      // Navigator.pushReplacementNamed(context,LoginPage.sName);
    });
    this._incrementCounter();
  }

  void luchWeb() {
    Navigator.pushNamed(context, 'login');
    launch('https://www.baidu.com/', enableJavaScript: true, forceWebView: true, statusBarBrightness: null);
  }

  Future<Null> _incrementCounter() async {
    final SharedPreferences prefs = await _prefs;
    final int counter = (prefs.getInt('counter') ?? 0) + 1;
    print(counter);
    setState(() {
      _counter = counter;
    });
    prefs.setInt('counter', counter);
  }

  void _tap() {
    this._incrementCounter();
    this.luchWeb();
  }

  @override
  Widget build(BuildContext context) {
    return new Container(
      // padding: const EdgeInsets.all(8.0),
      alignment: Alignment.center,
      transform: Matrix4.rotationZ(0.1),
      child: new Column(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          mineTopWidge,
          new Text(_counter > 0 ? '$_counter' : ''),
          RaisedButton(
            onPressed: _tap,
            child: Text('Show Flutter homepage'),
          ),
        ],
      ),
      height: 400.0
    );
  }
}
